package com.mk.shardingjdbcdemo.dao;

import com.mk.shardingjdbcdemo.entity.OrderItem;
import com.mk.shardingjdbcdemo.vo.OrderInfoVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderItemDao extends JpaRepository<OrderItem, Long> {

    @Query(value = "select a.*,b.num,b.price from t_order as a inner join t_order_item as b on a.order_id = b.order_id and a.order_id=:orderId", nativeQuery = true)
    List<OrderInfoVo> all(@Param("orderId") long orderId);

    @Query(value = "select a.*,b.num,b.price from t_order as a inner join t_order_item as b on a.order_id = b.order_id", nativeQuery = true)
    List<OrderInfoVo> all();
}
